<%@ page language="java" import="java.util.*, java.text.*,com.zjut.zs.util.tools.*,com.zjut.an.util.tools.*,com.zjut.an.util.system.*,
com.zjut.zs.school.manager.*, com.zjut.zs.school.dao.*,com.zjut.zs.user.manager.*, com.zjut.zs.user.dao.*,com.zjut.zs.cj.manager.*,
com.zjut.an.config.manager.*, com.zjut.an.config.dao.*, com.zjut.zs.cj.dao.*" pageEncoding="utf-8"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>考生登录系统</title>
    <script type="text/javascript">
    var browser=navigator.appName
    var b_version=navigator.appVersion
    var version=b_version.split(";");
    var trim_Version=version[1].replace(/[ ]/g,"");
    if(trim_Version=="MSIE9.0"||trim_Version=="MSIE8.0"||trim_Version=="MSIE7.0"||trim_Version=="MSIE6.0")
    {
        var returnVal = window.confirm("您的浏览器版本过低或者开启了兼容模式，无法使用本系统，点击确定跳转到帮助页面查阅登录方法", "标题");
        if(returnVal) {
            window.location.href = "../admin/soft.html";
        }else{
            window.location.href = "../admin/soft.html";
        }
    }
    </script>
    <script src="css/tailwindcss.css"></script>
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#3b82f6',
                        secondary: '#64748b',
                        success: '#10b981',
                        danger: '#ef4444',
                        warning: '#f59e0b'
                    }
                }
            }
        }
    </script>
    <script type="text/javascript" src="../plugins/assets/plugins/jquery-3.5.1.min.js"></script>
    <style>
        .password-toggle {
            cursor: pointer;
            transition: opacity 0.2s;
        }
        .password-toggle:hover {
            opacity: 0.7;
        }
        .form-input:focus {
            box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
        }
    </style>
</head>

<body class="bg-gray-50 min-h-screen flex items-center justify-center py-8">
<div class="w-full max-w-md mx-auto">

<%
AnConfigManager anconfig = (AnConfigManager) SpringContextUtil.getBean("AnConfigManager");
ZsSchoolManager zsManager = (ZsSchoolManager) SpringContextUtil.getBean("ZsSchoolManager");
ZsSchool school = new ZsSchool();
school = (ZsSchool)zsManager.getDataByInstance(1,1,null,null,school).getObjects().get(0);

//生成随机数x，传递给生成验证码的servlet:AuthenCodeImage,以防止出现外网访问验证码不变的情况
Random random=new Random();
double x=random.nextDouble();
%>

<%if(Status.ON.getStatus().equals(school.getScLoginActive())){ //如果仍然可以登录%>
    <div class="bg-white rounded-xl shadow-lg border border-gray-100 p-8">
        <div class="text-center mb-8">
            <h1 class="text-2xl font-bold text-gray-800 mb-2">考生登录系统</h1>
            <p class="text-gray-600">请输入您的账号信息进行登录</p>
        </div>

        <form id="form1" action="" method="post" onsubmit="return adminlogin();" class="space-y-6">
            <!-- 身份证号输入 -->
            <div>
                <label for="usIdcard" class="block text-sm font-medium text-gray-700 mb-2">
                    考生身份证号 <span class="text-red-500">*</span>
                </label>
                <input id="usIdcard" name="usIdcard" type="text"
                       class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-transparent transition-colors duration-200 form-input"
                       placeholder="请输入身份证号码"
                       required
                       data-rule-idCard="true"
                       data-msg-required="身份证号不能为空"
                       data-msg-idCard="请输入有效的身份证号码"/>
            </div>
            <!-- 密码输入 -->
            <div>
                <label for="usPassword" class="block text-sm font-medium text-gray-700 mb-2">
                    密码 <span class="text-red-500">*</span>
                </label>
                <div class="relative">
                    <input id="usPassword" name="usPassword" type="password"
                           class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-transparent transition-colors duration-200 form-input pr-12"
                           placeholder="请输入登录密码"
                           required
                           minlength="6"
                           maxlength="20"
                           autocomplete="off"/>
                    <div class="absolute inset-y-0 right-0 pr-3 flex items-center">
                        <img src="images/eye.png" class="password-toggle w-5 h-5" id="img" alt="显示密码" onclick="togglePassword()"/>
                    </div>
                </div>
            </div>

            <!-- 验证码输入 -->
            <div>
                <label for="rand" class="block text-sm font-medium text-gray-700 mb-2">
                    验证码 <span class="text-red-500">*</span>
                </label>
                <div class="flex space-x-3">
                    <input type="text" id="rand" name="rand"
                           class="flex-1 px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-transparent transition-colors duration-200 form-input"
                           placeholder="请输入验证码"
                           required/>
                    <div class="flex items-center space-x-2">
                        <img style="cursor:pointer;width:80px;height:40px;"
                             alt="验证码"
                             onclick="changeValidateCode()"
                             ver_colorofnoisepoint="#888888"
                             id="JD_Verification1"
                             src="../getValidateImage.action?x=<%=x %>"
                             class="border border-gray-300 rounded">
                        <button type="button" onclick="changeValidateCode()"
                                class="text-xs text-primary hover:text-primary-dark transition-colors duration-200 whitespace-nowrap">
                            换一个
                        </button>
                    </div>
                </div>
            </div>

            <!-- 登录按钮 -->
            <button type="submit"
                    class="w-full bg-primary hover:bg-primary-dark text-white font-medium py-3 px-4 rounded-lg transition-colors duration-200 focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2">
                登录系统
            </button>

            <!-- 消息提示 -->
            <div id="message" class="text-center text-sm text-danger"></div>

            <!-- 辅助链接 -->
            <div class="text-center space-y-2">
                <div class="text-sm text-gray-600">
                    <a href="zs_reg.jsp" class="text-primary hover:text-primary-dark transition-colors duration-200">
                        无法登录？请先注册
                    </a>
                </div>
                <div class="text-sm text-gray-600">
                    忘记密码？使用
                    <a href="getpassword1.jsp" class="text-primary hover:text-primary-dark transition-colors duration-200 font-medium">
                        【找回密码】
                    </a>
                </div>
            </div>
        </form>

        <script type="text/javascript">
            function togglePassword() {
                var pwd = document.getElementById('usPassword');
                var img = document.getElementById('img');
                if (pwd.type === 'password') {
                    pwd.type = 'text';
                    img.src = 'images/eye-close.png';
                } else {
                    pwd.type = 'password';
                    img.src = 'images/eye.png';
                }
            }
        </script>
    </div>
<%}else{ %>
   <div class="bg-white rounded-xl shadow-lg border border-gray-100 p-8 text-center">
        <div class="text-xl font-semibold text-gray-800 mb-4">暂停登录</div>
        <div class="text-gray-600"><%out.print(anconfig.getSingleConfigInfoByName("暂停登录需知")); %></div>
   </div>
<%} %>
</div>

<script src="../plugins/assets/plugins/jquery-3.5.1.min.js" type="text/javascript"></script>
<script src="../plugins/assets/plugins/jquery-validation-1.14.0/dist/jquery.validate.js" type="text/javascript"></script>
<script src="../plugins/assets/plugins/jquery-validation-1.14.0/dist/jquery.metadata.js" type="text/javascript"></script>
<script src="js/formvalidate.js" type="text/javascript"></script>
<script src="../admin/js/publicManager.js" type="text/javascript" charset="utf-8"></script>



<script type="text/javascript">
    $.ajaxSetup({ cache: false });

function adminlogin() {

		if ($("#usIdcard").val() == "") {
			$("#message").html("登录账号必须填写！");
		} else if ($("#usPassword").val() == "") {
			$("#message").html("登录密码必须填写！");
		} else if ($("#rand").val() == "") {
			$("#message").html("验证码必须填写！");
		} else {
			var jsonString = JSON.stringify(serializeToJSONSimply('#form1'));
			//console.info(jsonString);
			$.ajax({
		    	cache: false,
		    	type: "POST",
		        url:'../zsUserLogin.action?randnum='+Math.floor(Math.random()*1000000),
		        data:{rowstr:jsonString},// 你的formid
		        async: false,
		        error: function(request) {
		        	alert("网络错误，无法连接到服务器。");
		        },
		        success: function(data) {
		        	console.log(data);
		        	if(data.message=="success"){
		            	//alert("登录成功");
		            	window.top.location.reload(true);
		            	//window.top.location = './main.jsp'; ///当用ajax访问 时候成功的时候就自动的跳转过去
		        	} else if(data.message=="randfailed"){
		            	$("#message").html("登录失败，验证码错误！");
		        		alert("登录失败，验证码错误！");
		        		changeValidateCode();
		        	} else if(data.message=="timefailed"){
		            	$("#message").html("密码错误超过5次，请于60秒稍后再试！");
		        		alert("密码错误超过5次，请于60秒稍后再试！");
		        		changeValidateCode();
		        	} else if(data.message=="activefailed"){
		            	$("#message").html("考生尚未注册，请到考生注册中注册设置登录密码！");
		        		alert("考生尚未注册，请到考生注册中注册设置登录密码！");
		        		changeValidateCode();
		        	} else {
		        		$("#message").html("登录失败，用户名或密码错误！");
		        		alert("登录失败，用户名或密码错误！");
		        		changeValidateCode();
		        	}
		        }
		    });
		}
		return false;
	}


function changeValidateCode() {
        //这和浏览器的缓存机制有关系，也可以把页面设置为不缓存，这样就不用这个参数了。"nocache="+new Date().getTime()
        document.getElementById("JD_Verification1").src=document.getElementById("JD_Verification1").src + "?nocache="+new Date().getTime();

 }   
	</script>
</body>

</html>
